package com.keyancompany.zhongbaopingtai.utils;

import android.content.Context;
import android.text.TextUtils;
import android.view.Gravity;
import android.view.View;
import android.widget.TextView;
import android.widget.Toast;

import com.keyancompany.zhongbaopingtai.R;


/**
 * Toast统一管理类
 */
public class T {

    private T() {
        /* cannot be instantiated */
        throw new UnsupportedOperationException("cannot be instantiated");
    }

    public static boolean isShow = true;

    /**
     * 短时间显示Toast
     *
     * @param context
     * @param message
     */
    public static void showShort(Context context, CharSequence message) {
        if (isShow)
            show(context, message);
    }

    private static void show(Context context, CharSequence message) {
        Toast toast = new Toast(context);
        View layout = View.inflate(context, R.layout.layout_toast, null);
        TextView title = (TextView) layout.findViewById(R.id.toast_content);
        if (!TextUtils.isEmpty(message)) {
            title.setText(message);
            toast.setGravity(Gravity.BOTTOM, 0, 200);
            toast.setDuration(Toast.LENGTH_SHORT);
            // 替换掉原有的ToastView
            toast.setView(layout);
            toast.show();
        }
    }

    private static void show1(Context context, CharSequence message, int offxset) {
        Toast toast = new Toast(context);
        View layout = View.inflate(context, R.layout.layout_toast, null);
        TextView title = (TextView) layout.findViewById(R.id.toast_content);
        if (!TextUtils.isEmpty(message)) {
            title.setText(message);
            toast.setGravity(Gravity.BOTTOM, 0, offxset);
            toast.setDuration(Toast.LENGTH_SHORT);
            // 替换掉原有的ToastView
            toast.setView(layout);
            toast.show();
        }
    }

    private static void show(Context context, int message) {
        Toast toast = new Toast(context);
        View layout = View.inflate(context, R.layout.layout_toast, null);
        TextView title = (TextView) layout.findViewById(R.id.toast_content);
        title.setText(message);
        toast.setGravity(Gravity.BOTTOM, 0, 200);
        toast.setDuration(Toast.LENGTH_SHORT);
        // 替换掉原有的ToastView
        toast.setView(layout);
        toast.show();
    }

    /**
     * 短时间显示Toast
     *
     * @param context
     * @param message
     */
    public static void showShort(Context context, int message) {
        if (isShow)
            show(context, message);
    }

    /**
     * 长时间显示Toast
     *
     * @param context
     * @param message
     */
    public static void showLong(Context context, CharSequence message) {
        if (isShow)
            show(context, message);
    }

    /**
     * 长时间显示Toast
     *
     * @param context
     * @param message
     */
    public static void showLong(Context context, int message) {
        if (isShow)
            show(context, message);
    }

    /**
     * 自定义显示Toast时间
     *
     * @param context
     * @param message
     * @param duration
     */
    public static void show(Context context, CharSequence message, int duration) {
        if (isShow)
            show(context, message);
    }

    /***
     * 向下移动一点
     */
    public static void show(Context context, CharSequence message, int duration, int offset) {
        if (isShow)
            show1(context, message, offset);
    }

    /**
     * 自定义显示Toast时间
     *
     * @param context
     * @param message
     * @param duration
     */
    public static void show(Context context, int message, int duration) {
        if (isShow)
            show(context, message);
    }

}